<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class User_oplog_model extends Xt_model {

	protected $mTable = 'user_oplog';

	public function get_info_by_id($id, $fields='*')
	{
		return $this->get_by_id($id, $fields);
	}

    /**
     * 记录用户操作日志
     * @param $table 表名，操作了哪个数据表
     * @param $op 操作内容，格式为json，样例：{"type":"update", "contant":{"field":"value"}}
    */
    public function insert_oplog($table,$type='',$set_data='',$where='') {
        if (!$set_data) {
            return false;
        }
        $log_data = array('type'=>$type, 'contant'=>array('set'=>$set_data,'where'=>$where));
        $insert_data = array();
        //判断是前台或是后台用户
        if (!$opuserid = $this->session->userdata('admin_id')) {
            $insert_data['op_userid'] = $this->loginUser['id'];
            $insert_data['op_username'] = $this->loginUser['username'];
        } else {
            $insert_data['op_userid'] = $opuserid;
            $insert_data['op_username'] =$this->session->userdata('user_name');
        }
        $insert_data['table'] = $table;
        $insert_data['operation'] = json_encode($log_data);
        $insert_data['op_time'] = time();
        $this->db->insert($this->mTable, $insert_data);
        return true;
    }

}